<?php
if(!isset($_SESSION))
{
	session_start();
}
$usname = $_SESSION['fullname'];
include '../operations/connection.php';
$selectregular = mysql_query("Select sas.*,emp.FullName,emp.EmployeeCode FROM sa_regulation_salary sas,employee emp 
WHERE emp.IDEmployee = sas.employeeID AND emp.State = 1 AND emp.IDEmployee != '1322887525530'");
$number_of_page = ceil ( mysql_num_rows( $selectregular ) / $rows_per_page );
?>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.price_format.1.7.js"></script>
<script type="text/javascript" src="js/jquery.price_format.1.7.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
	$('#basicsalary').priceFormat({
		prefix: '',
		centsLimit: 0,
		centsSeparator: '',
		thousandsSeparator: ','
	});
	$('#allowancebasicsalary').priceFormat({
		prefix: '',
		centsLimit: 0,
		centsSeparator: '',
		thousandsSeparator: ','
	});
	$('#allowanceC').priceFormat({
		prefix: '',
		centsLimit: 0,
		centsSeparator: '',
		thousandsSeparator: ','
	});
	$('#allowance_senior').priceFormat({
		prefix: '',
		centsLimit: 0,
		centsSeparator: '',
		thousandsSeparator: ','
	});
	$('#insuranceSalary').priceFormat({
		prefix: '',
		centsLimit: 0,
		centsSeparator: '',
		thousandsSeparator: ','
	});
				
});

function hateyou(){
	$(document).ready(function() {
		$('#basicsalary').priceFormat({
			prefix: '',
			centsLimit: 0,
			centsSeparator: '',
			thousandsSeparator: ','
		});
		$('#allowancebasicsalary').priceFormat({
			prefix: '',
			centsLimit: 0,
			centsSeparator: '',
			thousandsSeparator: ','
		});
		$('#allowanceC').priceFormat({
			prefix: '',
			centsLimit: 0,
			centsSeparator: '',
			thousandsSeparator: ','
		});
		$('#allowance_senior').priceFormat({
			prefix: '',
			centsLimit: 0,
			centsSeparator: '',
			thousandsSeparator: ','
		});
		$('#insuranceSalary').priceFormat({
			prefix: '',
			centsLimit: 0,
			centsSeparator: '',
			thousandsSeparator: ','
		});
	});		
}
</script>
<script type="text/javascript">
function enterTable(e,value){
    var key = window.event ? e.keyCode : e.which;
    if (key == 13 || key == 8 || key == 46  || key == 37 || key == 39 ) {
    	if(key==13){
    		var j = 0;
    		var listID = new Array();
    		listID = listID.concat(["nameemployee","basicsalary","allowancebasicsalary","allowanceC","allowance_senior","insuranceSalary","user_create","first_create_update","user_last_update","time_last_update"]);	
    		for (j = 0; j < listID.length; j++){	
    			if (listID[j] == value) {	
    				if (j == listID.length - 1) {
    					return false;
    				}
    				document.getElementById(listID[j + 1]).focus();
    				document.getElementById(listID[j + 1]).select();
    				return false; 
    			}
    		}
    		
    		return false;
    	}else
    		return true;	
    }else if ( key < 48 || key > 57 ) {
        return false;
    }
    else return true;			
}

function processCheck(tenid,field){
	if(document.getElementById(tenid).checked == true){
		for(var i = 0;i<field.length;i++)
	    {
			field[i].checked = false ;
	    }
		document.getElementById(tenid).checked = true;
	 	var gtid=document.getElementById(tenid).value;
	 	var lang = '<?=$_SESSION['lang']?>';
	 	var usname = '<?=$usname?>';

	 	var page = '<?=$page?>';
	 	$.ajax({url:"content_salary/process-check-regular-salary.php",data:{idemployee:gtid,newlang:lang,usname:usname,page:page},success:function(result){
	 		document.getElementById("dvLstSalaryregular").innerHTML=result;
	 		hateyou();
	 		 	}
	 	});
	 	
	}else{
	document.getElementById(tenid).checked=false;
		//reset();
		if(document.getElementById('Update')!=""){
			document.getElementById('createSalary').style.visibility='hidden';
			document.getElementById('createSalary').style.display='none';
			document.getElementById('Update').style.visibility='visible';
			document.getElementById('Update').style.display='inline';
			document.getElementById('Update').setAttribute("class", "buttonNormalDisable");
			document.getElementById('Update').setAttribute("type", "button");
			
		}
		if(document.getElementById('createSalary')!=""){
			document.getElementById('createSalary').style.visibility='visible';
			document.getElementById('createSalary').style.display='inline';
			document.getElementById('Update').style.visibility='visible';
			document.getElementById('Update').style.display='inline';
			document.getElementById('createSalary').setAttribute("class", "buttonNormalDisable");
			document.getElementById('createSalary').setAttribute("type", "button");
			document.getElementById('Update').setAttribute("class", "buttonNormalDisable");
			document.getElementById('Update').setAttribute("type", "button");
			
		}	
		reset();
	}
}

function pagingregularsalary(page){
	
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
	    {

	        document.getElementById("showdata").innerHTML=xmlhttp.responseText;
	        
	    }
	  }
	var lang = '<?=$_SESSION['lang']?>';
	reset();
	$('input:checkbox').removeAttr('checked');
	
	xmlhttp.open("GET","content_salary/paging-regular-salary.php?page="+page,true);
	xmlhttp.send();
}

function reset(){
	document.getElementById('idemployee').value="";
	document.getElementById('nameemployee').value="";
	document.getElementById('basicsalary').value="";
	document.getElementById('allowancebasicsalary').value="";
	document.getElementById('allowanceC').value="";
	document.getElementById('allowance_senior').value="";
	document.getElementById('user_create').value="";
	document.getElementById('first_create_update').value="";
	document.getElementById('user_last_update').value="";
	document.getElementById('time_last_update').value="";
	document.getElementById('insuranceSalary').value="";
}

function resetChild(){
	var lang = '<?=$_SESSION['lang']?>';
	$('input:checkbox').removeAttr('checked');

	$.ajax({url:"content_salary/resetChildSalaryRegulation.php",data:{newlang:lang},success:function(result){
 		document.getElementById("dvLstSalaryregular").innerHTML=result;
 		hateyou();
 		 	}
 	});
}
</script>
<script type="text/javascript">
$(document).ready(function(){
	<?php 
	if (isset($_SESSION['alertupdate'])){?>
		alert("<?=$l_capnhatthanhcong?>");
	<?php unset($_SESSION['alertupdate']);}
	?>
	<?php 
			if (isset($_SESSION['alertinsert'])){?>
				alert("<?=$l_themthanhcong?>");
			<?php unset($_SESSION['alertinsert']);}
			?>
	
	});
</script>
<div id="contains">
	<div class="title" style="padding-top: 5px;font-weight: bold;"><?php echo $l_accountant;?> &rarr; <?php echo $l_ml_tinh_luong;?> &rarr; <?php echo $l_setup_regulation;?> &rarr; <?php echo $l_regulation_salary;?></div>
	<div class="content_code">
		<div class="approval-right" id="contentsalary">

			<div id="showdata">
				<form action="#" name="formCheck" method="post">
				<input type="hidden" id="usname" name="usname" value="<?=$usname?>">
					<table class="cssTable" border="1" style="width: 100%;">
						<thead>
							<tr>
								<th scope="col" style="width: 5%; border-right: 1px solid"></th>
								<th scope="col" style="width: 13%; border-right: 1px solid"><?php echo $l_employeecode?></th>
								<th scope="col" style="width: 20%; border-right: 1px solid"><?php echo $l_employee_name?></th>
								<th scope="col" style="width: 13%; border-right: 1px solid;height: 45px; "><?php echo $l_basicsalary;?></th>
								<th scope="col" style="width: 13%; border-right: 1px solid"><?php echo $l_allowancebasicsalary;?></th>
								<th scope="col" style="width: 12%; border-right: 1px solid"><?php echo $l_allowanceC;?></th>
								<th scope="col" style="width: 12%; border-right: 1px solid"><?php echo $l_allowanceSenior;?></th>
								<th scope="col" style="width: 12%"><?php echo $l_salaryforinsurance?></th>
							</tr>
						</thead>
						<tbody>
						<?php
						if(mysql_num_rows($selectregular)>0){
							$i=0;
							while ($row = mysql_fetch_array($selectregular)){
								if ( $i >= $page_start ){
									?>

							<tr>
								<td><input type="checkbox" name="checkregularsal"
									id="<?php echo 'checkcus'.$i?>"
									onclick="processCheck(this.id,document.formCheck.checkregularsal);"
									value="<?=$row[employeeID]?>" /></td>
								<td><?php echo $row[EmployeeCode];?></td>
								<td><?php echo $row[FullName]?></td>
								<td><?php echo number_format($row[basic_salary]);?></td>
								<td><?php echo number_format($row[allowance_basic_salary]);?></td>
								<td><?php echo number_format($row[allowance_c]);?></td>
								<td><?php echo number_format($row[allowance_senior]);?></td>
								<td><?php echo number_format($row[salary_insurance]);?></td>
							</tr>
							<?php }
							$i++;
							if ($i >= $page_end){
								break;
							}
							}
						}?>

							<tr>
								<td colspan="8" class="rf-dt-shdr-c"><span
									style="background: #eeeeee; padding: 1px; display: inline-block;width: 900px;">

									<?php if ( $number_of_page > 1 )
									{
										if ($page==1)
										$p=2;
										else if ($page==$number_of_page)
										$p=$number_of_page-1;
										else $p=$page;
										if($page!=1){?> <a href="salary.php?content=regulation_salary&page=<?=1?>"><span
											class='button_next'><?php echo "<<<";?> </span> </a> <a 
											href="salary.php?content=regulation_salary&page=<?=($page-1)?>"><span
											class='button_next'><?php echo "<<";?> </span> </a> <?php  }
											else{
												echo "<span class='button_next'><<<</span> ";
												echo "<span class='button_next'><<</span> ";
											}
											for ( $i = $p-1; $i <= $p+1; $i++ ) {
												if ($i<=$number_of_page && $i>0)

												if ($i==$page){
													echo "<span class='button_next' style='color: blue;'><b>".$i."</b></span>";
												}else{?> 
													<a href="salary.php?content=regulation_salary&page=<?=$i?>">
													<span class="button_next" ><?php echo $i;?> </span> </a> <?php
												}
												?> <?php
											}

											if($page!=$number_of_page){ ?> <a 
											href="salary.php?content=regulation_salary&page=<?=($page+1)?>"><span
											class='button_next'><?php echo ">>";?> </span> </a> <a 
											href="salary.php?content=regulation_salary&page=<?=($number_of_page)?>)?>"><span
											class='button_next'><?php echo ">>>";?> </span> </a> <?php }
											else{
												echo "<span class='button_next'>>></span> ";
												echo "<span class='button_next'>>>></span> ";
											}
									}


									?> </span>
								</td>
							</tr>
						</tbody>
					</table>
				</form>
			</div>
			<div
				style="margin: 10px 7px 5px 3px; color: #508E21; border-bottom: 1px dotted silver">
				<?php echo $l_allowanceemplsalary;?>
			</div>

			<div id="dvLstSalaryregular">
				<form action="#">
					<table style="border-bottom: 1px dotted silver; padding: 10px 5px"
						width="100%">
						<tr>
							<td class="tdfirst"><?php echo $l_employeecode;?>:</td>
							<td><input type="text" name="idemployee" readonly="readonly"
								id="idemployee" class="in_testfield"
								style="width: 516px; background: #eaeaea" /></td>
						</tr>
						<tr>
							<td class="tdfirst"><?php echo $l_employee_name;?>:</td>
							<td><input type="text"
								onkeypress="return enterTable(event,this.id);"
								name="nameemployee" id="nameemployee" class="in_testfield"
								style="width: 516px; background: #eaeaea" /></td>
						</tr>
						<tr>
							<td class="tdfirst"><?php echo $l_basicsalary;?>:</td>
							<td><input type="text"
								value="<?=number_format($_REQUEST['basicsalary'])?>"
								onkeypress="return enterTable(event,this.id);" name="basicsalary"
								id="basicsalary" class="in_testfield" style="width: 516px" /></td>
						</tr>
						<tr>
							<td class="tdfirst"><?php echo $l_allowancebasicsalary;?>:</td>
							<td><input type="text"
								value="<?=number_format($_REQUEST['allowancebasicsalary'])?>"
								onkeypress="return enterTable(event,this.id);"
								name="allowancebasicsalary" id="allowancebasicsalary"
								class="in_testfield" style="width: 516px" /></td>
						</tr>
						<tr>
							<td class="tdfirst"><?php echo $l_allowanceC;?>:</td>
							<td><input type="text"
								value="<?=number_format($_REQUEST['allowanceC'])?>"
								onkeypress="return enterTable(event,this.id);" id="allowanceC"
								name="allowanceC" class="in_testfield" style="width: 516px" />
							</td>
						</tr>
						<tr>
							<td class="tdfirst"><?php echo $l_allowanceSenior;?>:</td>
							<td><input type="text"
								value="<?=number_format($_REQUEST['allowance_senior'])?>"
								onkeypress="return enterTable(event,this.id);" name="allowance_senior"
								id="allowance_senior" class="in_testfield" style="width: 516px" />
							</td>
						</tr>
						
						<tr>
							<td class="tdfirst"><?php echo $l_salaryforinsurance;?>:</td>
							<td><input type="text"
								value="<?=number_format($_REQUEST['insuranceSalary'])?>"
								onkeypress="return enterTable(event,this.id);" name="insuranceSalary"
								id="insuranceSalary" class="in_testfield" style="width: 516px" />
							</td>
						</tr>
						
						<tr>
							<td class="tdfirst"><?php echo $l_user_create;?>:</td>
							<td><input type="text"
								onkeypress="return enterTable(event,this.id);" id="user_create"
								name="user_create" class="in_testfield" style="width: 516px" />
							</td>
						</tr>
						<tr>
							<td class="tdfirst"><?php echo $l_first_create;?>:</td>
							<td><input type="text"
								onkeypress="return enterTable(event,this.id);"
								id="first_create_update" name="first_create_update"
								class="in_testfield" style="width: 516px" />
							</td>
						</tr>
						<tr>
							<td class="tdfirst"><?php echo $l_user_last_update;?>:</td>
							<td><input type="text"
								onkeypress="return enterTable(event,this.id);"
								id="user_last_update" name="user_last_update"
								class="in_testfield" style="width: 516px" />
							</td>
						</tr>
						<tr>
							<td class="tdfirst"><?php echo $l_time_last_update;?>:</td>
							<td><input type="text"
								onkeypress="return enterTable(event,this.id);"
								id="time_last_update" name="time_last_update"
								class="in_testfield" style="width: 516px" />
							</td>
						</tr>
					</table>

					<table style="border-bottom: 1px dotted silver; padding: 10px 5px"
						width="100%">
						<tr>
							<td class="tdfirst" style="background: none;"></td>
							<td style="padding-left: 45px">
								<input  id="createSalary" name="createSalary" type="button" value="<?php echo $l_create;?>" class="buttonNormalDisable" />
								<input id="Update" name="update" type="button" value="<?php echo $l_update;?>" class="buttonNormalDisable" />
								<input id="Reset" name="Reset" type="reset" onclick="reset();" value="<?php echo $l_reset;?>" class="buttonNormal" />
							</td>
						</tr>
					</table>
				</form>
			</div>


		</div>
	</div>
</div>
